package com.abocode.jfaster.platform.common.tag.easyui;

import com.abocode.jfaster.core.util.ConvertUtils;
import com.abocode.jfaster.platform.view.TemplateView;
import com.abocode.jfaster.platform.util.JspWriterUtils;
import com.abocode.jfaster.platform.util.MutiLangUtils;
import com.abocode.jfaster.platform.util.SysThemesUtils;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

/**
 *
 * @author  张代浩
 *
 */
public class BaseTag extends TagSupport {
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	protected String type = "default";// 加载类型
	protected String cssTheme ;

	public String getCssTheme() {
		return cssTheme;
	}


	public void setCssTheme(String cssTheme) {
		this.cssTheme = cssTheme;
	}

	public void setType(String type) {
		this.type = type;
	}


	public int doStartTag() throws JspException {
		return EVAL_PAGE;
	}

	public int doEndTag() throws JspTagException {
		JspWriter out = this.pageContext.getOut();
		JspWriterUtils.write(out,end());
		return EVAL_PAGE;
	}

	public String end() {
		StringBuffer sb = new StringBuffer();
		TemplateView sysThemesEnum = SysThemesUtils.getSysTheme((HttpServletRequest) super.pageContext.getRequest());
		String types[] = type.split(",");
		//插入多语言脚本
		String lang = (String)((HttpServletRequest) this.pageContext.getRequest()).getSession().getAttribute("lang");
		if(StringUtils.isEmpty(lang)){
			lang= MutiLangUtils.DEFUALT_LANG;
		}

		String langjs ="<script type=\"text/javascript\" src=\"plug-in/mutiLang/"+lang+".js\"></script>";
		sb.append(langjs);
		if (ConvertUtils.isIn("jquery-webos", types)) {
			sb.append("<script type=\"text/javascript\" src=\"plug-in/sliding/js/jquery-1.7.1.min.js\"></script>");
		} else if (ConvertUtils.isIn("jquery", types)) {
			sb.append("<script type=\"text/javascript\" src=\"plug-in/jquery/jquery-1.8.3.js\"></script>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/jquery/jquery.cookie.js\" ></script>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/jquery-plugs/storage/jquery.storageapi.min.js\" ></script>");
		}
		if (ConvertUtils.isIn("ckeditor", types)) {
			sb.append("<script type=\"text/javascript\" src=\"plug-in/ckeditor/ckeditor.js\"></script>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/tools/ckeditorTool.js\"></script>");
		}
		if (ConvertUtils.isIn("ckfinder", types)) {
			sb.append("<script type=\"text/javascript\" src=\"plug-in/ckfinder/ckfinder.js\"></script>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/tools/ckfinderTool.js\"></script>");
		}
		if (ConvertUtils.isIn("easyui", types)) {
			sb.append("<script type=\"text/javascript\" src=\"plug-in/tools/dataformat.js\"></script>");
			sb.append(SysThemesUtils.getEasyUiTheme(sysThemesEnum));
			sb.append(SysThemesUtils.getEasyUiMainTheme(sysThemesEnum));
			sb.append(SysThemesUtils.getEasyUiIconTheme(sysThemesEnum));
//			sb.append("<link rel=\"stylesheet\" href=\"plug-in/easyui/themes/icon.css\" type=\"text/css\"></link>");
			sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"plug-in/accordion/css/accordion.css\">");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/easyui/jquery.easyui.min.1.3.2.js\"></script>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/easyui/locale/zh-cn.js\"></script>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/tools/syUtil.js\"></script>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/easyui/extends/datagrid-scrollview.js\"></script>");
		}
		if (ConvertUtils.isIn("DatePicker", types)) {
			sb.append("<script type=\"text/javascript\" src=\"plug-in/My97DatePicker/WdatePicker.js\"></script>");
		}
		if (ConvertUtils.isIn("jqueryui", types)) {
			sb.append("<link rel=\"stylesheet\" href=\"plug-in/jquery-ui/css/ui-lightness/jquery-ui-1.9.2.custom.min.css\" type=\"text/css\"></link>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/jquery-ui/js/jquery-ui-1.9.2.custom.min.js\"></script>");
		}
		if (ConvertUtils.isIn("jqueryui-sortable", types)) {
			sb.append("<link rel=\"stylesheet\" href=\"plug-in/jquery-ui/css/ui-lightness/jquery-ui-1.9.2.custom.min.css\" type=\"text/css\"></link>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/jquery-ui/js/ui/jquery.ui.core.js\"></script>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/jquery-ui/js/ui/jquery.ui.widget.js\"></script>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/jquery-ui/js/ui/jquery.ui.mouse.js\"></script>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/jquery-ui/js/ui/jquery.ui.sortable.js\"></script>");
		}
		if (ConvertUtils.isIn("prohibit", types)) {
			sb.append("<script type=\"text/javascript\" src=\"plug-in/tools/prohibitutil.js\"></script>");		}
		if (ConvertUtils.isIn("designer", types)) {
			sb.append("<script type=\"text/javascript\" src=\"plug-in/designer/easyui/jquery-1.7.2.min.js\"></script>");
			sb.append("<link rel=\"stylesheet\" href=\"plug-in/designer/easyui/easyui.css\" type=\"text/css\"></link>");
			sb.append("<link rel=\"stylesheet\" href=\"plug-in/designer/easyui/icon.css\" type=\"text/css\"></link>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/designer/easyui/jquery.easyui.min.1.3.0.js\"></script>");

			//加载easyui多语言
			sb.append("<script type=\"text/javascript\" src=\"plug-in/designer/easyui/locale/"+lang+".js\"></script>");

			sb.append("<script type=\"text/javascript\" src=\"plug-in/tools/syUtil.js\"></script>");
			sb.append("<script type=\'text/javascript\' src=\'plug-in/jquery/jquery-autocomplete/lib/jquery.bgiframe.min.js\'></script>");
			sb.append("<script type=\'text/javascript\' src=\'plug-in/jquery/jquery-autocomplete/lib/jquery.ajaxQueue.js\'></script>");
			sb.append("<script type=\'text/javascript\' src=\'plug-in/jquery/jquery-autocomplete/jquery.autocomplete.min.js\'></script>");
			sb.append("<link href=\"plug-in/designer/designer.css\" type=\"text/css\" rel=\"stylesheet\" />");
			sb.append("<script src=\"plug-in/designer/draw2d/wz_jsgraphics.js\"></script>");
			sb.append("<script src=\'plug-in/designer/draw2d/mootools.js\'></script>");
			sb.append("<script src=\'plug-in/designer/draw2d/moocanvas.js\'></script>");
			sb.append("<script src=\'plug-in/designer/draw2d/draw2d.js\'></script>");
			sb.append("<script src=\"plug-in/designer/MyCanvas.js\"></script>");
			sb.append("<script src=\"plug-in/designer/ResizeImage.js\"></script>");
			sb.append("<script src=\"plug-in/designer/event/Start.js\"></script>");
			sb.append("<script src=\"plug-in/designer/event/End.js\"></script>");
			sb.append("<script src=\"plug-in/designer/connection/MyInputPort.js\"></script>");
			sb.append("<script src=\"plug-in/designer/connection/MyOutputPort.js\"></script>");
			sb.append("<script src=\"plug-in/designer/connection/DecoratedConnection.js\"></script>");
			sb.append("<script src=\"plug-in/designer/task/Task.js\"></script>");
			sb.append("<script src=\"plug-in/designer/task/UserTask.js\"></script>");
			sb.append("<script src=\"plug-in/designer/task/ManualTask.js\"></script>");
			sb.append("<script src=\"plug-in/designer/task/ServiceTask.js\"></script>");
			sb.append("<script src=\"plug-in/designer/gateway/ExclusiveGateway.js\"></script>");
			sb.append("<script src=\"plug-in/designer/gateway/ParallelGateway.js\"></script>");
			sb.append("<script src=\"plug-in/designer/boundaryevent/TimerBoundary.js\"></script>");
			sb.append("<script src=\"plug-in/designer/boundaryevent/ErrorBoundary.js\"></script>");
			sb.append("<script src=\"plug-in/designer/subprocess/CallActivity.js\"></script>");
			sb.append("<script src=\"plug-in/designer/task/ScriptTask.js\"></script>");
			sb.append("<script src=\"plug-in/designer/task/MailTask.js\"></script>");
			sb.append("<script src=\"plug-in/designer/task/ReceiveTask.js\"></script>");
			sb.append("<script src=\"plug-in/designer/task/BusinessRuleTask.js\"></script>");
			sb.append("<script src=\"plug-in/designer/designer.js\"></script>");
			sb.append("<script src=\"plug-in/designer/mydesigner.js\"></script>");

		}
		if (ConvertUtils.isIn("tools", types)) {
			sb.append(SysThemesUtils.getCommonTheme(sysThemesEnum));
			sb.append(SysThemesUtils.getLhgdialogTheme(sysThemesEnum));
			sb.append(SysThemesUtils.getTabTheme(sysThemesEnum));
			sb.append("<script type=\"text/javascript\" src=\"plug-in/tools/curdtools_"+lang+".js\"></script>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/tools/easyuiextend.js\"></script>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/jquery-plugs/hftable/jquery-hftable.js\"></script>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/tools/json2.js\" ></script>");
		}
		if (ConvertUtils.isIn("toptip", types)) {
			sb.append("<link rel=\"stylesheet\" href=\"plug-in/toptip/css/css.css\" type=\"text/css\"></link>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/toptip/manhua_msgTips.js\"></script>");
		}
		if (ConvertUtils.isIn("autocomplete", types)) {
			sb.append("<link rel=\"stylesheet\" href=\"plug-in/jquery/jquery-autocomplete/jquery.autocomplete.css\" type=\"text/css\"></link>");
			sb.append("<script type=\"text/javascript\" src=\"plug-in/jquery/jquery-autocomplete/jquery.autocomplete.min.js\"></script>");
		}
		if (ConvertUtils.isIn("jeasyuiextensions", types)) {
			sb.append("<script src=\"plug-in/jquery-extensions/release/jquery.jdirk.min.js\" type=\"text/javascript\"></script>");
			sb.append("<link href=\"plug-in/jquery-extensions/icons/icon-all.css\" rel=\"stylesheet\" type=\"text/css\" />");
			sb.append("<link href=\"plug-in/jquery-extensions/jeasyui-extensions/jeasyui.extensions.css\" rel=\"stylesheet\" type=\"text/css\" />");
			sb.append("<script src=\"plug-in/jquery-extensions/jeasyui-extensions/jeasyui.extensions.js\" type=\"text/javascript\"></script>");
			sb.append("<script src=\"plug-in/jquery-extensions/jeasyui-extensions/jeasyui.extensions.linkbutton.js\" type=\"text/javascript\"></script>");
			sb.append("<script src=\"plug-in/jquery-extensions/jeasyui-extensions/jeasyui.extensions.menu.js\" type=\"text/javascript\"></script>");
			sb.append("<script src=\"plug-in/jquery-extensions/jeasyui-extensions/jeasyui.extensions.panel.js\" type=\"text/javascript\"></script>");
			sb.append("<script src=\"plug-in/jquery-extensions/jeasyui-extensions/jeasyui.extensions.window.js\" type=\"text/javascript\"></script>");
			sb.append("<script src=\"plug-in/jquery-extensions/jeasyui-extensions/jeasyui.extensions.dialog.js\" type=\"text/javascript\"></script>");
			sb.append("<script src=\"plug-in/jquery-extensions/jeasyui-extensions/jeasyui.extensions.datagrid.js\" type=\"text/javascript\"></script>");
		}
		return sb.toString();
	}

}

